aboutsummaryrefslogtreecommitdiff
path: root/pages/api/v2/etc/recent/[page].js
blob: 19495c1764a04f0a3a737fa183b564033df1ca54 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const API_URL = process.env.API_URI;

export default async function handler(req, res) {
  try {
    const page = req.query.page || 1;

    var hasNextPage = true;
    var datas = [];

    async function fetchData(page) {
      const data = await fetch(
        `${API_URL}/meta/anilist/recent-episodes?page=${page}&perPage=30&provider=gogoanime`
      ).then((res) => res.json());

      const filtered = data?.results?.filter((i) => i.type !== "ONA");
      hasNextPage = data?.hasNextPage;
      datas = filtered;
    }

    await fetchData(page);

    return res.status(200).json({ hasNextPage, results: datas });
  } catch (error) {
    res.status(500).json({ error });
  }
}